package bank.main;

import java.util.ArrayList;

import bank.exception.DepositException;
import bank.exception.NotFoundAccountException;
import bank.exception.WithdrawalException;
import bank.passbook.service.PassbookService;
import bank.passbook.vo.Passbook;
import bank.savingspassbook.service.SavingspassbookService;
import bank.savingspassbook.vo.SavingsPassbook;

public class BankMain {

	public static void main(String[] args) throws Exception {
		test();
	}

	private static void test() throws Exception {
		ArrayList<Passbook> list = new ArrayList<Passbook>();
		PassbookService service = PassbookService.getInstance();
		Passbook pb = null; 
		
		System.out.println("****************************************************");
		System.out.println("*********************예금 계좌 조회*********************");
		System.out.println("****************************************************");
		System.out.println("전체 예금 계좌 조회");
		list = service.findPassbookList();
		for (Passbook passbook : list) {
			System.out.println(passbook);
		}
		
		//예금 계좌 조회
		System.out.println("1111-1111 예금 계좌 조회");
		System.out.println(service.findPassbookByAccountNo("1111-1111"));

		//예금 계좌 입금(10만원)
		try {
			System.out.println("1111-1111 예금 계좌 입금(10만원)");
			service.depositMoney("1111-1111", 100000);
			System.out.println("1111-1111 예금 계좌 조회(입금 후)");
			pb = service.findPassbookByAccountNo("1111-1111");
			System.out.println(pb);			
		} catch (DepositException e) {
			e.printMessage();
		} 

		//예금 계좌 출금(200만원)
		try {
			System.out.println("1111-1111 예금 계좌 출금(200만원)");
			service.withdrawal("1111-1111", 2000000);
			System.out.println("1111-1111 예금 계좌 조회(출금 후)");
			pb = service.findPassbookByAccountNo("1111-1111");
			System.out.println(pb);	
		} catch (NotFoundAccountException e) {
			e.printMessage();
		} catch (WithdrawalException e) {
			e.printMessage();
		} 
		
		//예금 계좌 출금(20만원)
		try {
			System.out.println("1111-1111 예금 계좌 출금(20만원)");
			service.withdrawal("1111-1111", 200000);
			System.out.println("1111-1111 예금 계좌 조회(출금 후)");
			pb = service.findPassbookByAccountNo("1111-1111");
			System.out.println(pb);	
		} catch (NotFoundAccountException e) {
			e.printMessage();
		} catch (WithdrawalException e) {
			e.printMessage();
		}
		
		ArrayList<SavingsPassbook> list2 = new ArrayList<SavingsPassbook>();
		SavingspassbookService service2 = SavingspassbookService.getInstance();
		SavingsPassbook spb = null;
		
		System.out.println("****************************************************");
		System.out.println("*********************적금 계좌 조회*********************");
		System.out.println("****************************************************");
		
		System.out.println("전체 적금 계좌 조회");
		list2 = service2.findSavingsPassbookList();
		for (SavingsPassbook savingsPassbook : list2) {
			System.out.println(savingsPassbook);
		}
		
		System.out.println("1111-2222 예금 계좌 조회");
		System.out.println(service2.findSavingsPassbookByAccountNo("1111-2222"));

		//적금 계좌 입금(10만원)
		try {
			System.out.println("1111-2222 적금 계좌 입금(10만원)");
			service2.depositMoney("1111-2222", 100000);
			System.out.println("1111-2222 적금 계좌 조회(입금 후)");
			spb = service2.findSavingsPassbookByAccountNo("1111-2222");
			System.out.println(spb);			
		} catch (DepositException e) {
			e.printMessage();
		}

		//적금 계좌 출금(200만원)
		try {
			System.out.println("6666-2222 적금 계좌 출금(200만원)");
			service2.withdrawal("6666-2222", 2000000);
			System.out.println("6666-2222 적금 계좌 조회(출금 후)");
			spb = service2.findSavingsPassbookByAccountNo("1111-2222");
			System.out.println(spb);			
		} catch (NotFoundAccountException e) {
			e.printMessage();
		} catch (WithdrawalException e) {
			e.printMessage();
		}
		
		//적금 계좌 출금(200만원)
		try {
			System.out.println("2222-2222 적금 계좌 출금(20만원)");
			service2.withdrawal("2222-2222", 200000);
			System.out.println("2222-2222 적금 계좌 조회(출금 후)");
			spb = service2.findSavingsPassbookByAccountNo("2222-2222");
			System.out.println(spb);			
		} catch (NotFoundAccountException e) {
			e.printMessage();
		} catch (WithdrawalException e) {
			e.printMessage();
		}
		
		System.out.println("****************************************************");
		System.out.println("*********************계좌 이자 적립*********************");
		System.out.println("****************************************************");
		service.interestAccrues();
		service2.interestAccrues();
		
		System.out.println("전체 예금 계좌 조회");
		list = service.findPassbookList();
		for (Passbook passbook : list) {
			System.out.println(passbook);
		}
		System.out.println("전체 적금 계좌 조회");
		list2 = service2.findSavingsPassbookList();
		for (SavingsPassbook savingsPassbook : list2) {
			System.out.println(savingsPassbook);
		}
	}
}
